#ifndef DRV_UART_H
#define DRV_UART_H

#include <fcntl.h>
#include <termios.h>
#include "includes.h"
#include <linux/serial.h>

#define RS485_1 "/dev/ttyS1"
#define RS485_2 "/dev/ttyS3"

#define MAXQSIZE 10	//最大队列长度

typedef struct{
    int length;
    int flag;
    uint8_t tx_queue_buff[100];
}tx_queue_data_t;

typedef struct {
	tx_queue_data_t *base; //初始化的动态分配存储分配空间
	int front;	//头指针，若队列不空，指向队头元素
	int rear;	//尾指针，若队列不空，指向队尾元素的下一个位置
}tx_queue_t;

extern tx_queue_t tx_queue[MAXQSIZE];
extern tx_queue_data_t tx_queue_buff[MAXQSIZE][MAXQSIZE];

extern int baudflag_arr[];
extern int speed_arr[];

extern struct termios oterm_attr;
extern struct itimerval tick;

int speed_to_flag(int speed);
int setup_port(int fd, int baud, int databits, int parity, int stopbits);
int read_data(int fd, void *buf, int len);
int write_data(int fd, void *buf, int len);
int reset_port(int fd);

int tx_queue_init(tx_queue_t* q, tx_queue_data_t* b);
int tx_queue_in(tx_queue_t* q, tx_queue_data_t e);
int tx_queue_out(tx_queue_t *q, tx_queue_data_t *e);
#endif // VDATA_RS232_H
